package top.huntwolf.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.huntwolf.admin.common.JsonResult;
import top.huntwolf.admin.pojo.topical.Topical;
import top.huntwolf.admin.pojo.topical.TopicalBook;
import top.huntwolf.admin.pojo.topical.TopicalBookList;
import top.huntwolf.admin.service.TopicalService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Api(description = "专题分类控制器")
@RestController
@CrossOrigin
@RequestMapping(value = "/topical")
public class TopicalController {


    @Autowired
    TopicalService topicalService;


    // 增
    @PostMapping("")
    public JsonResult addTopical(@RequestBody Topical topical) {
        topicalService.add(topical);
        return JsonResult.success(null);
    }

    // 删
    @DeleteMapping("/{tid}")
    public JsonResult deleteTopical(@PathVariable Integer tid) {
        topicalService.delete(tid);
        return JsonResult.success(null);
    }

    // 改
    @PutMapping("")
    public JsonResult updateTopical(@RequestBody Topical topical) {
        topicalService.update(topical);
        return JsonResult.success(null);
    }

    // 查 -- 专题查
    @ApiOperation("topical为图书专题")
    @GetMapping("byTopical")
    public JsonResult getTopical() {
//        List<TopicalBook> list = topicalService.getByTopical();
//       Map<String,List<TopicalBook> > map = topicalService.getByTopical();
        List<TopicalBookList> bookList = topicalService.getByTopical();
        return JsonResult.success(bookList);
    }


    // 查  -- 精选清单查
    @GetMapping("bySelectedList")
    @ApiOperation("selectedList为精选清单")
    public JsonResult getSelectedList() {
//        Map<String,List<TopicalBook> > map = topicalService.getSelectedList();
        List<TopicalBookList> list = topicalService.getSelectedList();
        return JsonResult.success(list);
    }


    // 查 -- 热销查
    @GetMapping("isHot")
    @ApiOperation("是否为热搜")
    public JsonResult getHotTropical() {
        List<TopicalBook> list = topicalService.getHotTropical();
        return JsonResult.success(list);
    }
}
